import {
  createRouter,
  createWebHashHistory,
} from 'vue-router'
import MyLogin from '@/components/MyLogin.vue';
import MyRegister from '@/components/MyRegister.vue';
import MyLayout from '@/components/MyLayout';
import MyCenter from '@/pages/MyCenter'
import MyZhuye from '@/pages/MyZhuye'
import MyOrder from '@/pages/MyOrder.vue';
import AllArea from '@/pages/AllArea.vue';
import MyShopping from '@/pages/MyShopping'
import OrderAll from '@/secondpage/OrderAll'
import OrderWeifukuan from '@/secondpage/OrderWeifukuan'
import OrderDaishouhuo from '@/secondpage/OrderWeishouhuo'
import MyItem from '@/pages/MyItem'
import MyAddress from '@/pages/MyAddress'
import MyCity from '@/pages/MyCity'
import MySort from '@/pages/MySort'
import HouTaiLogin from '@/components/HouTaiLogin'
import HouTai from '@/components/HouTai'
import ItemManage from '@/HouTaipages/ItemManage'
import AreaManage from '@/HouTaipages/AreaManage'
import ItemKind from '@/HouTaipages/ItemKind'
import LunBo from '@/HouTaipages/LunBo'
import OrderManage from '@/HouTaipages/OrderManage'
import MiaoSha from '@/HouTaipages/MiaoSha'
import MyMiaosha from'@/pages/miaosha.vue'
const routes = [
  {
    path:'/',
    component:MyLayout,
    children:[
      {
        path: '/Sort/:SortName',
        name:'sort',
        component: MySort,
        meta: {
          title: '某件商品',
         },
      },
      {
        path: '/City/:CityName',
        name:'City',
        component: MyCity,
        meta: {
          title: '特色地区',
         },
      },
        {
          path: '/Item/:id',
          name:'Item',
          component: MyItem,
          meta: {
            title: '商品',
           },
        },
        {
          path:'/MyMiaoSha',
          name:'MyMiaosha',
          component:MyMiaosha,
          meta:{
            title:'秒杀商品'
          }
        },
        {
        path:'/Address',
        component:MyAddress,
        meta: {
          title: '我的地址',
         },
      },
      {
        path:'',
        component:MyZhuye, 
        meta: {
          title: '',
         },         
      },
      {
        path:'/Center',
        component:MyCenter, 
        meta: {
          title: '个人中心',
         },        
      },
      {
        path:'/Area',
        component:AllArea, 
        meta: {
          title: '全部地区',
         },        
      },
      {
        path:'/Order',
       component:MyOrder,
       meta: {
        title: '我的订单',
       }, 
       children:[
        {path:'/Order',
         component:OrderAll,
         meta: {
          title: '全部订单',
         },
      },
      {path:'/DaiShouhuo',
      component:OrderDaishouhuo,
      meta: {
        title: '待收货',
       },
   },
   {path:'/Weifukuan',
   component:OrderWeifukuan,
   meta: {
    title: '待付款',
   }, 
},
       ]
      },
      {
        path:'/Shopping',
       component:MyShopping,
       meta: {
        title: '购物车',
       },
      }
    ],
  },
    {
      path: '/Login',
    component: MyLogin,
    meta: {
      isAuth: true,
      title: '登录'
    }

  },
  {
    path: '/Register',
    component: MyRegister,
    meta: {
      isAuth: false,
      title: '注册'
    },
   },
   {
    path: '/houtaiLogin',
  component: HouTaiLogin,
  meta: {
    isAuth: true,
    title: '后台登录'
  }

},
{
  path: '/houtai',
component:HouTai,
children:[
  {path:'/ItemManage',
  component:ItemManage,},
  {
    path:'/AreaManage',
    component:AreaManage
  },
  {
    path:'/ItemKind',
    component:ItemKind
  },
  {
    path:'/LunBo',
    component:LunBo
  },
  {
    path:'/OrderManage',
    component:OrderManage
  },
  {
    path:'/MiaoSha',
    component:MiaoSha
  }
],
meta: {
  isAuth: true,
  title: '后台管理系统',
},

},
   
    
    {beforeEnter: (to, from, next) => {
      console.log(to,from);
      next()
      //独享的守卫有前置无后置
    }
  },
  
]
// 创建路由对象
const router = createRouter({
  history: createWebHashHistory(),
  routes
})
//路由前置守卫；用来设置元信息
router.beforeEach((to,from,next)=>{
  if(to.meta.title){
    document.title=to.meta.title
  }
  next()
})
//前置路由守卫-初始化和路由切换之前会进行调用
// router.beforeEach((to, from, next) => {
 
  // console.log(to, from);
  // if (to.meta.isAuth === true) {
    // next()
  
  // else {
    // alert('没有权限')
  // }
// })
//后置守卫
router.afterEach((to) => {
  document.title = to.meta.title || '赣南农产品'
  // console.log(to, from);
})
export default router;
